'''
Created on Jan 23, 2015

@author: dewey
'''


from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QTAgg as NavigationToolbar


from PyQt5.QtCore import *
from PyQt5.QtWidgets import *


from ui_gen.Ui_pyproxy_chartview import Ui_PyProxyChartview

DPI_DEFAULT = 100

class PyProxyChartview(QMainWindow, Ui_PyProxyChartview):
    
    def __init__(self, parent=None):
        super(PyProxyChartview, self).__init__(parent)



    def create_main_frame(self):
        self.main_frame = QWidget()
        # Create the mpl Figure and FigCanvas objects.
        # 5x4 inches, 100 dots-per-inch
        #
        self.dpi = DPI_DEFAULT
        self.fig = Figure((5.0, 4.0), dpi=self.dpi)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self.main_frame)
        # Since we have only one plot, we can use add_axes
        # instead of add_subplot, but then the subplot
        # configuration tool in the navigation toolbar wouldn't
        # work.
        #
        self.axes = self.fig.add_subplot(111)
        # Bind the 'pick' event for clicking on one of the bars
        #
        self.canvas.mpl_connect('pick_event', self.on_pick)
        # Create the navigation toolbar, tied to the canvas
        #
        self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
        #
        # Layout with box sizers
        #

        vbox = QVBoxLayout()
        vbox.addWidget(self.canvas)
        vbox.addWidget(self.mpl_toolbar)
        self.main_frame.setLayout(vbox)
        self.setCentralWidget(self.main_frame)

    def set_figure(self, fig, dpi):
        self.fig = fig
        self.fig.set_dpi(self.dpi)
        self.canvas.figure = self.fig
        self.canvas.draw()
    
    def on_pick(self, event):
        print("picked!")
        